export default class Tactic {
  constructor(info) {
    // 赋值战法属性
    Object.assign(this, info);
  }
  /**
   * 战法是否演练
   */
  get isPractice() {
    // stateData.userTactics
    let ids = [];
    try {
      ids = window.stateData.userTactics || [];
    } catch (err) {
      console.log(err);
    }
    return ids.indexOf(this.id) !== -1;
  }
  // 获取战法等级名称
  get qualityName() {
    let arr = ["C", "B", "A", "S"];
    return arr[this.quality - 1];
  }
  // 获取战法类型名称
  get typeName() {
    let obj = {
      1: "指挥",
      2: "主动",
      3: "突击",
      4: "被动",
      5: "兵种",
      6: "阵法",
      7: "内政",
    };
    return obj[this.type];
  }
  get effectTypeName() {
    let obj = {
      1: "治疗",
      2: "增益",
      3: "援护",
      4: "内政",
      5: "兵刃单体",
      6: "兵刃群体",
      7: "谋略单体",
      8: "谋略群体",
      9: "控制",
      10: "减益",
    };
    return obj[this.effect_type];
  }
  get fromType() {
    if (this.born_tactic_heroes && this.born_tactic_heroes.length) {
      return 1; // 自带战法
    } else if (
      this.inherit_tactic_heroes &&
      this.inherit_tactic_heroes.length
    ) {
      return 2; // 传承战法
    } else if (this.from_tactic_events && this.from_tactic_events.length) {
      return 3; // 事件战法
    } else {
      return -1;
    }
  }
  /**
   * 判断战法是否是某种来源类型
   * @param {*} types []
   * 1 武将自带 2武将传承 3事件战法
   */
  isFrom(types = []) {
    let isOk = false;
    types.some((type) => {
      if (
        type == 1 &&
        this.born_tactic_heroes &&
        this.born_tactic_heroes.length
      )
        isOk = true;
      else if (
        type == 2 &&
        this.inherit_tactic_heroes &&
        this.inherit_tactic_heroes.length
      )
        isOk = true;
      else if (
        type == 3 &&
        this.from_tactic_events &&
        this.from_tactic_events.length
      )
        isOk = true;
      return isOk;
    });
    return isOk;
  }
}
